using Common.Communal;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Product.API.Write.Applications.Commands.Process;

namespace Product.API.Write.Controllers
{
    /// <summary>
    /// 工序API-写
    /// </summary>
    [Route("api/[controller]")]
    [ApiController]
    public class ProcessController : ControllerBase
    {
        /// <summary>
        /// 中介者
        /// </summary>
        private readonly IMediator mediator;

        /// <summary>
        /// 构造方法
        /// </summary>
        /// <param name="mediator">中介者</param>
        public ProcessController(IMediator mediator)
        {
            this.mediator = mediator;
        }

        /// <summary>
        /// 工序添加
        /// </summary>
        /// <param name="command">请求</param>
        /// <returns>返回任务</returns>
        [HttpPost("CreateProcess")]
        public async Task<ApiResult<int>> CreateProcess(CreateProcessCommand command)
        {
            return await mediator.Send(command);
        }

        /// <summary>
        /// 工序修改
        /// </summary>
        /// <param name="command">请求</param>
        /// <returns>返回任务</returns>
        [HttpPost("UpdateProcess")]
        public async Task<ApiResult<int>> UpdateProcess(UpdateProcessCommand command)
        {
            return await mediator.Send(command);
        }

        /// <summary>
        /// 工序删除
        /// </summary>
        /// <param name="Id">主键</param>
        /// <returns>返回任务</returns>
        [HttpGet("DeleteProcess")]
        public async Task<ApiResult<int>> DeleteProcess(int Id)
        {
            DeleteProcessCommand command = new DeleteProcessCommand();
            command.Id = Id;
            return await mediator.Send(command);
        }

        /// <summary>
        /// 工序批量添加
        /// </summary>
        /// <param name="command">请求</param>
        /// <returns>返回任务</returns>
        [HttpPost("BatchProcess")]
        public async Task<ApiResult<int>> BatchProcess(BatchCreateProcessCommand command)
        {
            return await mediator.Send(command);
        }

        /// <summary>
        /// 工序批量修改
        /// </summary>
        /// <param name="command">请求</param>
        /// <returns>返回任务</returns>
        [HttpPost("BatchUpdateProcess")]
        public async Task<ApiResult<int>> BatchUpdateProcess(BatchUpdateProcessCommand command)
        {
            return await mediator.Send(command);
        }


    }
}


